<template>
	<view class="super-back-content" style="background: pink;">
		<!-- <component :is="showView"></component> -->
		<subHome v-show="currentView == 0" ref="subHome" @stopPullDown="stopPullDown"></subHome>
		<subMoney v-if="currentView == 1" ></subMoney>
		<subOrder v-if="currentView == 2" :navBar="navBar" ref="order"></subOrder>
		<subMe v-if="currentView == 3" ref="subMe"></subMe>
		<tabBar ref="tabBar" :device="device" @changeView="changeView" v-show="currentView != 1"></tabBar>
	</view>
</template>

<script>
	import tabBar from'../../components/sub-tabbar/tabBar.vue'
	import subHome from '../../components/sub-home/sub-home.vue'
	import subMoney from '../../components/sub-money/sub-money.vue'
	import subOrder from '../../components/sub-order/sub-order.vue'
	import subMe from '../../components/sub-me/sub-me.vue'
	export default{
		data(){
			return{
				device:65,
				currentView:0,
				apptoken:"",
				showView:"subHome",
				navBar:[{ type:"待操作" },{type:"待审核"},{type:"已失效"},{ type:"待评价" },{ type:"待返还" },{ type:"已返还" }], 
			}
		},
		onShow() {
			// if(this.currentView == 0){
			// 	this.$refs.subHome.getOrdering(null,null,1);
			// 	this.$refs.subHome.getWillOrder(null,null,1);
			// }
			
			//this.$refs.subMe.getUserInfo();
			
		},
		components:{
			tabBar,subHome,subMoney,subOrder,subMe
		},
		watch:{
			currentView(val){
				if(val == 0){
						this.$refs.subHome.checkOrderStatus();
				}
			}
		},
		onLoad(options) {
			//this.getHeight();
			//#ifdef APP-PLUS || MP-WEIXIN
			const device = this.$store.state.device;
			this.device = this.$CommonJS.GETDEVICE(device)
			//#endif
			this.apptoken = uni.getStorageSync("apptoken");
			//个人资料
			this.getCJFuserInfo();
			//订单
			this.getOrderCount();//订单总数量
			
			
		},
		onPullDownRefresh:function(){
			 this.$refs.subHome.getOrdering(null,null,1);
			 this.$refs.subHome.getWillOrder(null,null,1);
			
		 },
		methods:{
			stopPullDown(){
				uni.stopPullDownRefresh();
			},
			getOrderCount(){
				//订单总数量
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.user_orderCount,
					data:{apptoken:this.apptoken},
					success(res) {
						console.log(res);
						if(res.data.success){
							//将数量存入navBar数组，渲染
							const d = res.data.data;
							_this.navBar[0].num = d.dczOrderCount;//待操作
							_this.navBar[1].num = d.jxOrderCount;//待审核
							_this.navBar[2].num = d.CancelOrderCount;//已失效
							_this.navBar[3].num = d.dpjOrderCount;//待评价
							_this.navBar[4].num = d.dqrOrderCount;//待返还
							_this.navBar[5].num = d.lsOrderCount;//已完成
							//console.log(JSON.stringify(_this.navBar))
						}
					}
				})
			},
			getCJFuserInfo(){
				//个人资料
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.user_view,
					data:{apptoken:this.apptoken},
					success(res) {
						console.log(res)
						if(res.data.success){
							//_this.userInfo = res.data.data;
							let d = res.data.data;
							uni.setStorage({
								key:"taobaoID",
								data:d.taobaoID,
								success() {
									uni.setStorage({
										key:"CJFAddress",
										data:{
											receiver:d.receiver,
											receiverPhone:d.receiverPhone,
											sprovince:d.sprovince,
											scity:d.scity,
											sarea:d.sarea,
											address:d.address
										},
										success() {
											
										}
									})
								}
							})
						}
						
					}
				})
			},
			changeView(n){
				console.log(n)
				this.currentView = n;
				this.getOrderCount();
			},
			goOrder(n,type){
				//this.currentView = n;
				console.log(type)
				this.getOrderCount();
				this.$refs.tabBar.changeTab(n);
				if(type){
					this.$nextTick(function(){
						this.$refs.order.chageTabBar(type);
					})
				}
				
				
			},
			getHeight(){
				switch(uni.getSystemInfoSync().platform){
				    case 'android':
				       console.log('运行Android上')
				       break;
				    case 'ios':
				       console.log('运行iOS上')
				       break;
				    default:
				       console.log('运行在开发者工具上')
				       break;
				}
			}
		}
		
	}
</script>

<style scoped>
	@import url("super-back.css");
</style>
